using GrapeCity.Forguncy.Commands;
using GrapeCity.Forguncy.Plugin;
using GrapeCity.Forguncy.Log;
using System;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace FaissOperation
{
    [Icon("pack://application:,,,/FaissOperation;component/Resources/Icon.png")]
    [Designer("FaissOperation.Designer.FaissOperationServerCommandDesigner, FaissOperation")]
    [Category("嵌入式向量索引")]
    [OrderWeight(90)]
    public class Cluster_Check : Command, ICommandExecutableInServerSideAsync
    {
        [FormulaProperty]
        [DisplayName("集合名")]
        public object KBName { get; set; }

        [DisplayName("将检查结果保存到变量")]
        [Description("true：该集合存在；false：该集合不存在")]
        [ResultToProperty]
        public string ResultInParamater { get; set; } = "IsExist";


        public async Task<ExecuteResult> ExecuteAsync(IServerCommandExecuteContext dataContext)
        {
            var name = (await dataContext.EvaluateFormulaAsync(KBName))?.ToString() ?? "";

            // 检查集合名是否为空
            dataContext.Parameters[ResultInParamater] = CollectionManager.Instance.CollectionExists(name);
            return new ExecuteResult();
        }

        public override string ToString()
        {
            return "检查集合是否存在";
        }

        public override CommandScope GetCommandScope()
        {
            return CommandScope.ExecutableInServer;
        }


    }
}
